/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:38917
 * Date:2025/4/15
 * Time:13:34
 */
public class Solution {
    //
    public static boolean searchMatrix(int[][] matrix, int target) {
        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
            return false;
        }
        int rowLength = matrix.length;
        int colLength = matrix[0].length;
        for (int i = 0; i < rowLength; i++) {
            //判断target是否在本行范围内
            if (matrix[i][0] < target && matrix[i][colLength - 1] > target) {
                for (int j = 0; j < colLength; j++) {
                    if(matrix[i][j] == target) {
                        return true;
                    }
                }
                return false;
            }
            if (matrix[i][0] == target || matrix[i][colLength - 1] == target) {
                return true;
            }
        }
        return false;
    }
    //
    public static void main(String[] args) {
        boolean flg = searchMatrix(new int[][]{{1}}, 3);
        System.out.println(flg);
    }
}
